import Vue from 'vue'
import Vuex from 'vuex'
import { getStorage, setStorage, removeStorage } from '../utils/auth'
import getters from './getters'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: getStorage('jwt'),
    name: getStorage('name'),
    avatar: getStorage('avatar'),
    isLogin: getStorage('isLogin')
  },
  mutations: {
    SET_NAME: (state, name) => {
      state.name = name
      setStorage('name', name)
    },

    SET_TOKEN: (state, token) => {
      state.token = token
      setStorage('jwt', token)
    },

    REMOVE_TOKEN: (state) => {
      state.token = ''
      removeStorage('jwt')
    },

    SET_AVATAR: (state, val) => {
      state.avatar = val
      setStorage('avatar', val)
    },
    SET_LOGIN_STATE: (state, value) => {
      state.isLogin = value
      setStorage('isLogin', value)
    }
  },
  actions: {
  },
  modules: {
  },
  getters
})
